package com.sl.biz.modular.group.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.tree.Tree;
import com.sl.biz.modular.group.controller.domain.request.*;
import com.sl.biz.modular.group.controller.domain.response.SquareLakeGroupVO;
import com.sl.biz.modular.group.domain.dto.BizSquareLakeGroupDTO;
import com.sl.biz.modular.group.service.SquareLakeGroupBizService;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/group")
@RequiredArgsConstructor
public class SquareLakeGroupController {
    private final SquareLakeGroupBizService squareLakeGroupBizService;

    @SneakyThrows
    @PostMapping("/tree")
    public List<Tree<String>> tree(@RequestBody @Validated SquareLakeGroupTreeRequest addRequest) {
        return squareLakeGroupBizService.tree(addRequest.getRelationTypeCode(),
                addRequest.getProductId());
    }

    @SneakyThrows
    @PostMapping("/add")
    public String add(@RequestBody @Validated SquareLakeGroupAddRequest addRequest) {
        return squareLakeGroupBizService.add(addRequest);
    }


    @SneakyThrows
    @PostMapping("/update_by_id")
    public Boolean updateById(@RequestBody @Validated SquareLakeGroupUpdateRequest addRequest) {
        return squareLakeGroupBizService.updateById(addRequest);
    }

    @SneakyThrows
    @PostMapping("/delete_by_id")
    public Boolean deleteById(@RequestBody @Validated SquareLakeGroupDeleteByIdRequest addRequest) {
        return squareLakeGroupBizService.deleteById(addRequest);
    }


    @SneakyThrows
    @PostMapping("/get_by_id")
    public SquareLakeGroupVO getById(@RequestBody @Validated SquareLakeGroupGetByIdRequest addRequest) {
        BizSquareLakeGroupDTO byId = squareLakeGroupBizService.getById(addRequest);
        return BeanUtil.copyProperties(byId, SquareLakeGroupVO.class);
    }
}
